package cn.tedu.jdbc;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.util.Scanner;

//库名 tedu
// 表名 userinfo 【id,username,password,nickname,age】



//                                          插入Demo
public class JDBCDemo1 {
    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection= DriverManager.getConnection(
               "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
               "root",
               "root"
        );
        Scanner scan=new Scanner(System.in);
        System.out.println("请输入用户名");
        String userName=scan.nextLine();
        System.out.println("请输入密码");
        String password=scan.nextLine();
        System.out.println("请输入昵称");
        String nickName=scan.nextLine();
        System.out.println("请输入年龄");
        int age=scan.nextInt();
        scan.nextLine();
        Statement statement = connection.createStatement();
        String sql1="insert into userinfo(username,password,nickname,age) values ('"+userName+"','"+password+"','"+nickName+"',"+age+") ";

        int i = statement.executeUpdate(sql1);
        System.out.println("受影响的表记录为"+i+"条");
        connection.close();



    }
}
